<?php
declare (strict_types = 1);

namespace app\model;

use think\facade\Db;
use think\Model;

/**
 * @mixin \think\Model
 */
class Student extends Model
{

    /**
     * 获取学生分页
     */
    public static function pageList($data,$domain,$isFront=false) {
        $page = $data['page'];
        $size = $data['size'];
        $sname = isset($data['kw']) ? $data['kw'] : '';
        $size = $size + 0;
        $start = ($page -1) * $size;
        $sname = trim($sname);
        $select = Student::limit($start,$size);
        if($sname != '') {
            $select = $select->where('sname','like',$sname.'%');
            $total = self::where('sname','like',$sname.'%')->count();
        } else {
            $total = self::count();
        }
        $list = $select->select()->toArray();
        foreach ($list as &$stu){
            $stu['avatar'] = $domain.$stu['avatar'];
            $pictures = str_replace('/storage/',$domain.'/storage/',$stu['pictures']);
            if($isFront) {
                $stu['pictures'] = $pictures == '' ? [] : explode('$8$',$pictures);
            }
        }
        return compact('list','total');
    }




}
